uni.addInterceptor('request', {
	invoke(args) {
		console.log('invoke args: ', args)
		
		if (args.url.indexOf('/api/app/login') > -1) {
			return
		}
		if (!args.header || !args.header['sy-token']) {
			if (!args.header) {
				args.header = {}
			}
			const token = uni.getStorageSync('sy-token')
			if (token != null && token != undefined) {
				args.header['sy-token'] = uni.getStorageSync('sy-token')
			} else {
				uni.navigateTo({url:'/pages/login/login'})
			}
		}

		const userInfo = uni.getStorageSync('userInfo')
		console.log('userInfo: ', userInfo)
		if (userInfo == null || userInfo == undefined) {
			uni.navigateTo({url:'/pages/login/login'})
		} else {
			if (userInfo.phone == null || userInfo.phone == undefined) {
				uni.navigateTo({url:'/pages/login/login'})
			}
		}
	},
	success(args) {
		console.log('request interceptor, success: ', args)
		if (args.statusCode == 400) {
			console.log('request interceptor, 400: ', args)
			if (args.data.message.indexOf('token 无效') > -1) {
				this.redirectToLogin()
			} else if (args.data.message.indexOf('token 已过期') > -1) {
				this.redirectToLogin()
			} else if (args.data.message.indexOf('token 已被顶下线') > -1) {
				this.redirectToLogin()
			} else if (args.data.message.indexOf('token 已被踢下线') > -1) {
				this.redirectToLogin()
			}
		}
	},
	fail(err) {
		console.log('interceptor-request-fail', err)
	},
	complete(res) {
		
	},
	redirectToLogin() {
		uni.navigateTo({url:'/pages/login/login'})
	}
})
